package com.example.demo1122.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo1122.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author baomidou
 * @since 2023-12-09
 */
@Mapper
public interface CourseMapper extends BaseMapper<Course> {
    @Results(id = "courseResultMap", value = {
            @Result(property = "courseID", column = "courseID"),
            @Result(property = "courseName", column = "courseName")
    })

    @Select("SELECT courseID, courseName FROM course")
    List<Course> findAll();

    @Insert("INSERT INTO course (courseName, sysRole) VALUES (#{courseName}, #{sysRole})")
    @Options(useGeneratedKeys = true, keyProperty = "courseID")
    int insert(Course course);
    @Update("UPDATE course SET courseName=#{courseName}, sysRole=#{sysRole} WHERE courseID=#{courseID}")
    int update(Course course);

    @Select("SELECT COUNT(*) FROM course WHERE courseName=#{courseName}")
    int searchBycourseName(String courseName);

    @Delete("DELETE FROM course WHERE courseID = #{courseID}")
    int deleteById(@Param("courseID") Integer courseID);

    @Select("SELECT COUNT(*) FROM course WHERE courseID = #{courseID}")
    boolean isCourseIDExists(Course course);

    @ResultMap("courseResultMap")
    Page<Course> findPage(Page<Course> page, @Param("courseID") Integer courseID, @Param("courseName") String courseName);

    @Select("SELECT * FROM course WHERE courseName = #{courseName}")
    Course findByName(String courseName);

    Course getCourseInfo(Integer conversationID);

    int editSysRole(Course course);
}
